package anthology.daily_question._24_10;
//https://leetcode.cn/problems/find-the-first-player-to-win-k-games-in-a-row/description/?envType=daily-question&envId=2024-10-24
public class _3175找到连续赢K场比赛的第一位玩家 {
    //官方
    public int findWinningPlayer(int[] skills, int k) {
        int len = skills.length;
        int win = 0,i = 0,last_win = 0;
        while (i < len) {
            int j = i + 1;
            while(j<len && skills[i]>skills[j] && win<k){
                j++;
                win++;
            }
            if(win == k)
                return i;
            win = 1;
            last_win = i;
            i = j;
        }
        return last_win;
    }
    //灵神
    public int findWinningPlayer2(int[] skills, int k) {
        int maxI = 0;
        int win = 0;
        for(int i=1; i < skills.length && win < k; i++){
            if(skills[i] > skills[maxI]){
                maxI = i;
                win = 0;
            }
            win++;
        }
        return maxI;
    }
}
